﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Communication;

namespace Clipper.BLL.DetectChain
{
    public partial class Transportation
    {
        #region 滑轨定义
        /// <summary>
        /// 滑轨A，试剂1
        /// </summary>
        public static TransportControl TransportA = new TransportControl(Can.DW_R1_SA_ID, "HA", "HB", "HC", "HD");
        /// <summary>
        /// 滑轨B，试剂2
        /// </summary>
        public static TransportControl TransportB = new TransportControl(Can.R2_SUB_ID, "HE", "HF", "HG", "HH");
        /// <summary>
        /// 滑轨C,加底物
        /// </summary>
        public static TransportControl TransportC = new TransportControl(Can.R2_SUB_ID, "HI", "HJ", "HK", "HL");
        /// <summary>
        /// 滑轨D,洗板1
        /// </summary>
        public static TransportControl TransportD = new TransportControl(Can.R2_SUB_ID, "HP", "HS", "HR");
        /// <summary>
        /// 滑轨E,洗板2
        /// </summary>
        public static TransportControl TransportE = new TransportControl(Can.R2_SUB_ID, "HX", "HT", "HZ");
        /// <summary>
        /// 孵育箱滑轨
        /// </summary>
        public static TransportControl IncubationTransport = new TransportControl();
        #endregion
        /// <summary>
        /// 滑轨复位
        /// </summary>
        public static void Reset()
        {

            TransportA.Home();
            TransportB.Home();
            TransportC.Home();
            TransportD.Home();
            TransportE.Home();
            TransportC.WaitStatus(0);
            TransportD.WaitStatus(0);
            TransportE.WaitStatus(0);
            TransportA.WaitStatus(0);
            TransportB.WaitStatus(0);
            IncubationTransport.IncubationReset();
            IncubationTransport.WaitStatus(0);
           
        }
        /// <summary>
        /// 清理反应条
        /// </summary>
        public static void Clear()
        {   
            DetectionHouse.DetectControl.ThrowStrip();//清空检测仓的
            DetectionHouse.DetectControl.WaitStatus(4);
            ThrowStrip(null);//扔小车
            ReactionStripPosition positionBll = new ReactionStripPosition();
            List<Model.ReactionStripPosition> modelList= positionBll.GetModelList("");
            foreach (Model.ReactionStripPosition model in modelList)
            {
                switch (model.Position)
                {
                   case 71:
                        //扔试剂1
                        IncubationTransport.WaitStatus(IncubationTransport.R1());
                        ThrowStrip(TransportA);
                        break;
                    case 72:
                        IncubationTransport.WaitStatus(IncubationTransport.R2());
                        ThrowStrip(TransportB);
                        break;
                    case 73:
                        IncubationTransport.WaitStatus(IncubationTransport.Wash(1));
                        ThrowStrip(TransportD);
                        break;
                    case 74:
                        IncubationTransport.WaitStatus(IncubationTransport.Wash(2));
                        ThrowStrip(TransportE);
                        break;
                    case 75:
                        IncubationTransport.WaitStatus(IncubationTransport.Substrate());
                        ThrowStrip(TransportC);
                        break;
                    case 76:
                        DetectionHouse.DetectControl.WaitStatus(DetectionHouse.DetectControl.ThrowStrip());
                        break;
                    default:
                        IncubationTransport.WaitStatus(IncubationTransport.GetStrip(model.Position));
                        ThrowStrip(null);
                        break;
                }
                DetectChainHelper.UnPosition(model.Position);
            }
        }

        private static void ThrowStrip(TransportControl transport)
        {
            if (transport != null)//清空检测仓和小车上的
            {
                transport.WaitStatus(transport.GoIncubation());
            }
            IncubationTransport.WaitStatus(IncubationTransport.Detect_1());
            DetectionHouse.DetectControl.WaitStatus(DetectionHouse.DetectControl.GoIncubation());
            IncubationTransport.WaitStatus(IncubationTransport.Detect());
            DetectionHouse.DetectControl.WaitStatus(DetectionHouse.DetectControl.ThrowStrip());
            if (transport != null)
            {
                transport.Home();
            }
        }
        /// <summary>
        /// 暂停/恢复
        /// </summary>
        /// <param name="isPause">暂停true,恢复false</param>
        public static void Pause(bool isPause)
        {
            mIsPause = isPause;
            IncubationTransport.IsPause = isPause;
        }

        private static void StopRock()
        {
            IncubationBox.BedControl.StopRock();
            IncubationBox.BedControl.WaitStatus(1);
            IncubationBox.BedControl.Reset();

        }
    }
}
